/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */

import Vue from "vue";
import {Tooltip} from 'view-design'

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};

//页面状态相关
let status = {

  modalMessageSend: {
    isShow: false,
  },
  modalMessageAccount: {
    isShow: false,
  },
  modalMessageDetail: {
    isShow: false,
    message: {
      id: "",
      isAll: false,
      userId: "",
      pushPlatform: 0,
      messageAccount: "",
      type: 0,
      result: 0,
      createtime: "",
      content: "",
      user: {},
      title: "",
      isOpen: false,
      opentime: "",
    }
  },
  modalImage: {
    isShow: false,
    url: ''
  },
  rules: {
    title: [
      {required: true, message: '标题不能为空', trigger: 'blur'}
    ],
    content: [
      {required: true, message: '正文不能为空', trigger: 'blur'}
    ],
  },
  modalAssignUser:{
    isShow: false
  },
  modalStatusChange:{
    isShow: false,
    state:-1
  }

};

// 和网络交互相关的参数
let params = {
  //搜索条件
  searchParams: {
    userId: "",
    userName: "",
    searchAll:false,
    onlyUnread:true,
    assigned:'',
    sortBy: "createTime",
    searchUnReply: false,
    messageStatus: null,
    tag: null,
  },
  selectedEmployee:'',
  messageDetailParam: {
    messageId: ""
  },
  messageAccountParam: {
    firstName: "",
    encodeName:""
  },
  messageSendParam: {
    userId: "",
    userName: "",
    token: "",
    title: "",
    content: "",
  },
  messageStatusParam: {
    userId:"",
    userEncodeName:"",
    employeeId:'',
    employeeName:'',
    state:0
  },
  statusParam: {
    userId: "",
    statusId:"",
    state:0
  }
};

// 页面的数据源
let data = {
  messageList: [],
  accountList:[],
  employeeList:[],
  customerService: {
    employeeId: "",
    name: "",
    state: null,
    avator: "",
    createtime: null,
  }
};



let tableAccountTitles = function (self) {
  var titles = [
    {
      type: 'index',
      title: '#',
      width: 60,
      key: 'index',
      align: 'center',
    },
    {
      title: '头像',
      key: 'avatar',
      width: 80,
      align: 'center',
      render: (h, params) => {
        return (
          <div>
            <img src={params.row.avatar} height={50} onClick={() => {
              status.modalImage.url = params.row.avatar;
              status.modalImage.isShow = true;
            }}></img>
          </div>
        );
      }
    },
    {
      title: '用户名编号',
      key: 'userName',
      align: 'center',
      render: (h, params) => {
        if(!params.row.encodeName){
          let username = Vue.prototype.$tiyHideUsername(params.row.userName);
          return (<div>{username}</div>);
        }else{
          return (<div>{params.row.encodeName}</div>);
        }

      }
    },
    {
      title: '终端类型',
      width: 100,
      key: 'title',
      render: (h, params) => {
        let type = "";
        switch(params.row.deviceType){
          case 1:
            type = 'Android';
            break;
          case 2:
            type = 'IOS';
            break;
          case 3:
            type = 'PC';
            break;
          case 4:
            type = 'Mobile PC';
            break;
          default:
            break;
        }
        return (<div style="text-align:center">{type}</div>);
      }
    },
    {
      title: '推送令牌',
      width: 100,
      render: (h, params) => {
        return (
          <div>
            {(params.row.messageAccount !== null && params.row.messageAccount !== "" ? "已生成" : "未生成")}
          </div>
        );
      }
    },
    {
      title: '操作',
      key: 'action',
      //fixed: 'right',
      width: 100,
      align: 'center',
      render: (h, params) => {
        return h('a', {
          props: {
            // to: {
            //   path:"ChatMessageDetail/" + params.row.userId,
            //   query:{userName:params.row.userName}
            // },
            // tag: 'a',
          },
          attrs: {
            target: '_blank',
          },
          on: {
            click: () => {
              self.openChatWindow(params.row.userId,params.row.userName)
            }
          }
        }, '发送')
      }
    }
  ]

  return self.$authTableTitles(titles);

};

export default {
  tPage: page,
  tStatus: status,
  tParams: params,
  tData: data,
  // tableTitles: tableTitles,
  tableAccountTitles: tableAccountTitles,
};
